$(window).on('load', function () {
    getIndustryData();
});

/**
 *请求规模以上工业数据
 * */
var getIndustryData = function () {
    SGIS.API.post("/macro/get/above/industry").data({'year':2018}).json(function (re) {
        if(re){
            var data = re.data;
            var name = re.name;
            var unit = re.unit;
            var xAxis_data = [],data_val = [];
            for(var i = 0 ; i < data.length ; i++){
                var item_x = data[i][1]+"-"+data[i][2];
                xAxis_data.push(item_x);
                data_val.push(data[i][0])
            }
            renderBar(xAxis_data,data_val,unit,name);
        }else{
            return;
        }
    });

}
/**
 *绘制柱状图
 * */
var myChart_bar=''
var renderBar = function (xAxis_data,data_val,unit,name) {
    var dom = document.getElementById("scatter-map-bar");
    if(myChart_bar){
        myChart_bar.dispose()
    }
    myChart_bar = echarts.init(dom);
    var app = {};
    var option = null;
    app.title = 'data1';

    option = {
        color: ['#3398DB'],
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            },
            formatter: "{a} <br/>{b}: {c}"+unit
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            feature: {
                saveAsImage: {}
            }
        },
        xAxis : [
            {
                type : 'category',
                data : xAxis_data,
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        series : [
            {
                name:name,
                type:'bar',
                barWidth: '60%',
                data: data_val ,
                color: "#01bed9"
            }
        ]
    };
    if (option && typeof option === "object") {
        myChart_bar.setOption(option, true);
    }
}
